﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Collections;
using log4net;
using WEB.BLL.Entities;
using WEB.Exceptions;

namespace WEB.BLL.Services
{
    #region PermissionService

    /// <summary>
    /// PermissionService object for Ibatis mapped table 'Permission'.
    /// </summary>
    public class PermissionService : IPermissionService
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(PermissionService).Name);
        private static volatile PermissionService _PermissionService = null;
        public static PermissionService GetInstance()
        {
            if (_PermissionService == null)
            {
                lock (typeof(PermissionService))
                {
                    if (_PermissionService == null) // double-check
                        _PermissionService = new PermissionService();
                }
            }
            return _PermissionService;
        }
        public PermissionService()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public PermissionEntity LoadByRoleAndScreen(PermissionEntity objE)
        {
            try
            {
                return ExecuteQueryForObject<PermissionEntity>("PermissionLoadByRoleAndScreen", objE);
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public IList<PermissionEntity> LoadByRole(PermissionEntity objE)
        {
            try
            {
                return ExecuteQueryForList<PermissionEntity>("PermissionLoadByRole", objE);
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        public int UpdateViewAll(PermissionEntity objE)
        {
            try
            {
                ExecuteUpdate("PermissionUpdateViewAll", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public int UpdateAddAll(PermissionEntity objE)
        {
            try
            {
                ExecuteUpdate("PermissionUpdateAddAll", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public int UpdateEditAll(PermissionEntity objE)
        {
            try
            {
                ExecuteUpdate("PermissionUpdateEditAll", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public int UpdateDeleteAll(PermissionEntity objE)
        {
            try
            {
                ExecuteUpdate("PermissionUpdateDeleteAll", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public int UpdatePrintAll(PermissionEntity objE)
        {
            try
            {
                ExecuteUpdate("PermissionUpdatePrintAll", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public int UpdateImportAll(PermissionEntity objE)
        {
            try
            {
                ExecuteUpdate("PermissionUpdateImportAll", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public int UpdateExportAll(PermissionEntity objE)
        {
            try
            {
                ExecuteUpdate("PermissionUpdateExportAll", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
    }
    #endregion
}
